/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditStoreLocation.java
 *
 * Created on Jun 5, 2010, 10:11:17 PM
 */

package omg;

import omg.UserInterfaces.UserInt;

/**
 *
 * @author papkala
 */
public class EditStoreLocation extends javax.swing.JDialog {

    /** Creates new form EditStoreLocation */
    public EditStoreLocation(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        UserInt.getInstance().registerChangeStoreLocation(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        getStoreLocationChoser = new javax.swing.JFileChooser();
        jButton1 = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        storeLocation = new javax.swing.JTextField();

        getStoreLocationChoser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
        getStoreLocationChoser.setName("getStoreLocationChoser"); // NOI18N
        getStoreLocationChoser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                getStoreLocationChoserActionPerformed(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(omg.OMGApp.class).getContext().getResourceMap(EditStoreLocation.class);
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setName("saveButton"); // NOI18N

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        storeLocation.setEditable(false);
        storeLocation.setName("storeLocation"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .add(storeLocation, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton1))
                    .add(layout.createSequentialGroup()
                        .add(jButton3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(saveButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(storeLocation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 7, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(saveButton)
                    .add(jButton3))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        System.out.println("Closing 'edit store location window', all changes abandoned");
        this.dispose();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.getStoreLocationChoser.showOpenDialog(this);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void getStoreLocationChoserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getStoreLocationChoserActionPerformed
        if (!evt.getActionCommand().equalsIgnoreCase("CancelSelection")) {
            String path = this.getStoreLocationChoser.getSelectedFile().toString();
            this.storeLocation.setText(path);
        }
    }//GEN-LAST:event_getStoreLocationChoserActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                EditStoreLocation dialog = new EditStoreLocation(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser getStoreLocationChoser;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    public javax.swing.JButton saveButton;
    public javax.swing.JTextField storeLocation;
    // End of variables declaration//GEN-END:variables

}
